'use strict';

angular.module('app')
  .controller('loginCtrl', [
    '$scope',
    '$http',
    '$state',
    'cache',
    function($scope, $http, $state, cache) {
      $scope.submit = function() {
        $http.post('data/login.json', $scope.user)
          .then(function(success) {
              console.log(success);
              cache.put('id', success.id);
              cache.put('name', success.name);
              cache.put('image', success.image);
              $state.go('main');
            },
            function(error) {
              console.log(error);
            });
      };
    }
  ])
